package com.liliya.servlet.cate;

import com.liliya.pojo.Cate;
import com.liliya.service.impl.CateServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Description TODO
 * @Author hhy
 * @Date 2021/1/12 19:02
 */
@WebServlet(urlPatterns = "/subcate/main")
public class SubCateServlet extends HttpServlet {
    private CateServiceImpl cateService = new CateServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("来了");
        int num = 1;
        int total = cateService.totalCate();
        String p = req.getParameter("p");
        if (p != null) {
            num = Integer.parseInt(p);
        }
        int step = 5;
        int start = (num - 1) * 5 + 1;
        int end = start + step;
        List<Cate> cates = cateService.findCate(start, end);
        for (Cate cate : cates) {
            System.out.println(cate);
        }
        req.getSession().setAttribute("cates",cates);
        resp.sendRedirect(req.getContextPath()+"/cate/subcate.jsp");
    }
}
